package com.springbootblog.dao;

import com.springbootblog.dao.sqlBuilder.ArticleSqlBuilder;

import java.util.List;

import com.springbootblog.dao.sqlBuilder.ChatSqlBuilder;
import com.springbootblog.dao.sqlBuilder.UserSqlBuilder;
import com.springbootblog.pojo.*;
import org.apache.ibatis.annotations.*;

@Mapper//这个注解表示这是一个mybatis的mapper类，这个类中包含了对数据库的操作方法。
public interface ArticleDao
{
    /**
     * 获取博客首页数据总条数
     * @param search
     * @return
     */
    long selectBySearchAndPageNum(@Param("search") String search);

    /**
     * 获取博客首页数据列表
     * @param search
     * @param page
     * @param limit
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "selectBySearchAndPage")
    List<IndexArticle> selectBySearchAndPage(@Param("search") String search, @Param("startNum") Integer page, @Param("limit") Integer limit);

    /**
     * elasticsearch 批量写入数据
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getArticleList")
    List<Article> getArticleList();

    /**
     * 获取文章详情数据
     * @param article_id
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getArticleDetailById")
    Article getArticleDetailById(@Param("article_id") String article_id);

    /**
     * 获取文章标签数据
     * @param labelstr
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getLabelByIdStr")
    List<Label> getLabelByIdStr(@Param("labelstr") String labelstr);

    /**
     * 上一篇文章
     * @param article_id
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getFrontArticle")
    Article getFrontArticle(@Param("article_id") String article_id);

    /**
     * 下一篇文章
     * @param article_id
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getAfterArticle")
    Article getAfterArticle(@Param("article_id") String article_id);

    /**
     * 获取资源
     * @param resource_id
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getResourceById")
    Resource getResourceById(@Param("resource_id") Integer resource_id);

    /**
     * 添加浏览记录
     * @param browse
     * @return
     */
    @InsertProvider(type =ArticleSqlBuilder.class, method = "addBrowse")
//    @SelectKey(statement="select last_insert_id()", before=false, keyProperty="id", resultType=Integer.class, keyColumn="id") // keyProperty为对象中你想要的属性名，keyColumn为对应的数据库字段名
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer addBrowse(Browse browse);

    /**
     * 获取一级评论
     * @param article_id
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getCommontListByArticleId")
    List<Comment> getCommontListByArticleId(@Param("article_id") String article_id);

    /**
     * 获取二级评论
     * @param article_id
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getCommontTwoListByArticleId")
    List<Comment> getCommontTwoListByArticleId(@Param("article_id") String article_id, @Param("comment_id") String comment_id);

    /**
     * 获取回复评论信息
     * @param replyid
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getCommontByReplyId")
    Comment getCommontByReplyId(@Param("replyid") String replyid);

    /**
     *
     * @param cate_id
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getArtCategoryByCatePid")
    List<ArtCategory> getArtCategoryByCatePid(@Param("cate_id") String cate_id);

    /**
     *
     * @param cate_id_son
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getArtCategoryById")
    ArtCategory getArtCategoryById(@Param("cate_id_son") String cate_id_son);

    /**
     *
     * @param labelIdDecrypt
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getLabelInfoById")
    Label getLabelInfoById(@Param("labelIdDecrypt") String labelIdDecrypt);

    /**
     *
     * @param where
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "selectSearchPageNum")
    Long selectSearchPageNum(@Param("where") String where);

    /**
     *
     * @param where
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "selectSearchPage")
    List<IndexArticle> selectSearchPage(@Param("where") String where);

    /**
     *
     * @param article_id
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getCommentNumber")
    Long getCommentNumber(@Param("article_id") String article_id);

    /**
     *
     * @param cate_id
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getArtCategoryInfoById")
    ArtCategory getArtCategoryInfoById(@Param("cate_id") String cate_id);

    /**
     *
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getPlaceOnFileList")
    List<String> getPlaceOnFileList();

    /**
     *
     * @param year
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getPlaceOnFileListByYear")
    List<IndexArticle> getPlaceOnFileListByYear(@Param("year") String year);

    /**
     * 获取评论信息
     * @param replyid
     * @return
     */
    @SelectProvider(type =ArticleSqlBuilder.class, method = "getCommentInfo")
    Comment getCommentInfo(@Param("replyid") String replyid);

    /**
     * 添加评论
     * @param comment
     * @return
     */
    @InsertProvider(type = ArticleSqlBuilder.class, method = "addComment")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer addComment(Comment comment);

    /**
     * 访问量 + 1
     * @param article_id
     * @return
     */
    @UpdateProvider(type = ArticleSqlBuilder.class, method = "addClickNum")
    Integer addClickNum(@Param("article_id")String article_id);

}